﻿Imports System.Diagnostics

''' <summary>
''' 日志打点的简单实现。
''' </summary>
Public Class DefaultPopLogger
    Implements IPopLogger
    Public Const LOG_FILE_NAME As String = "topsdk.log"
    Public Const DATETIME_FORMAT As String = "yyyy-MM-dd HH:mm:ss"

    Shared Sub New()
        Try
            Trace.Listeners.Add(New TextWriterTraceListener(LOG_FILE_NAME))
        Catch e As Exception
            Trace.Listeners.Add(New TextWriterTraceListener(Console.Out))
        End Try
        Trace.AutoFlush = True
    End Sub

    Public Sub [Error](ByVal message As String) Implements IPopLogger.Error
        Trace.WriteLine(message, DateTime.Now.ToString(DATETIME_FORMAT) & " ERROR")
    End Sub

    Public Sub Warn(ByVal message As String) Implements IPopLogger.Warn
        Trace.WriteLine(message, DateTime.Now.ToString(DATETIME_FORMAT) & " WARN")
    End Sub

    Public Sub Info(ByVal message As String) Implements IPopLogger.Info
        Trace.WriteLine(message, DateTime.Now.ToString(DATETIME_FORMAT) & " INFO")
    End Sub
End Class